<template>
  <div>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="addproductAttributeCategory">添加</el-button>
      </div>
    </el-card>


    <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 2200px">
      <el-table-column label="编号" width="250">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="类型名称" width="250">
        <template slot-scope="scope">{{ scope.row.name }}</template>
      </el-table-column>
      <el-table-column label="属性数量" width="250">
        <template slot-scope="scope">{{ scope.row.attributeCount }}</template>
      </el-table-column>
      <el-table-column label="参数数量" width="250">
        <template slot-scope="scope">{{ scope.row.paramCount }}</template>
      </el-table-column>
      <el-table-column label="设置" width="350">
        <template slot-scope="scope">
        <el-button size="mini" @click="tiao(scope.row.id)">属性列表</el-button>
        <el-button size="mini" @click="canshu(scope.row.id)">参数列表</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      style="float: right; padding: 3px 0" type="text"
      :current-page=pageNum
      :page-sizes="[3  , 10  , 15]"
      :page-size=pageSize
      layout="total, sizes, prev, pager, next, jumper"
      :total=total>
    </el-pagination>


    <el-dialog title="添加类型" :visible.sync="dialogFormVisible" width="300px">
      <el-form :model="productAttributeCategory">
        <el-form-item label="类型名称" :label-width="formLabelWidth">
          <el-input style="width: 150px" v-model="productAttributeCategory.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="编辑类型" :visible.sync="dialogFormVisible2" width="300px">
      <el-form :model="productAttributeCategory">
        <el-form-item label="类型名称" :label-width="formLabelWidth">
          <el-input style="width: 150px" v-model="productAttributeCategory.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="update">确 定</el-button>
      </div>
    </el-dialog>


    <router-link to="productAttribute"></router-link>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {add, delect, page, update} from "@/api/product/productAttributeCategory";
import {findProductAttribute} from "@/api/product/productAttribute";

export default {
    //import引入的组件需要注入到对象中才能使用"
    components: {},
    props: {},
    data() {
      //这里存放数据"

      return {
        id:'',
        productAttributeCategory:{},
        productAttribute:{},
        formLabelWidth:'100px',
        tableData:{},
        pageNum:1,
        pageSize:3,
        total:'',
        total1:'',
        dialogFormVisible:false,
        dialogFormVisible2:false
      };
    },
    //计算属性 类似于data概念",
    computed: {},
    //监控data中的数据变化",
    watch: {},
    //方法集合",
    methods: {
      canshu(val){
          this.$router.push({path:'/product/productParm',query:{id:val}})
      },
      tiao(val){
          this.$router.push({path:'/product/productAttribute',query:{id:val}})
      },
      update(){
        update(this.productAttributeCategory).then(
          res=>{
            this.$message.success("修改成功")
            this.dialogFormVisible1=false
            this.productAttributeCategory=[]
            location.reload()
          }
        )
      },
      add(){
        add(this.productAttributeCategory).then(
          res=>{
            this.$message.success("添加成功")
            this.dialogFormVisible=false
            this.productAttributeCategory=[]
            location.reload()
          }
        )
      },
      addproductAttributeCategory(){
          this.productAttributeCategory={}
          this.dialogFormVisible=true
      },
      handleSizeChange(val) {
        this.pageSize=val
        this.findlist()
      },
      handleCurrentChange(val) {
        this.pageNum=val
        this.findlist()
      },
      handleDelete(val){
          delect(val.id).then(
            res=>{
              this.$message.success("删除成功")
              location.reload()
            }
          )
      },
      handleEdit(val){
        this.productAttributeCategory=val
         this.dialogFormVisible2=true
      },
      findlist(){
        page(this.pageNum,this.pageSize).then(
          res=>{
            this.tableData=res.data.rows
            this.total=res.data.total
          }
        )
      }
    },
    //生命周期 - 创建完成（可以访问当前this实例）",
    created() {
      this.findlist()
    },
    //生命周期 - 挂载完成（可以访问DOM元素）",
    mounted() {
    },
    beforeCreate() {
    }, //生命周期 - 创建之前",
    beforeMount() {
    }, //生命周期 - 挂载之前",
    beforeUpdate() {
    }, //生命周期 - 更新之前",
    updated() {
    }, //生命周期 - 更新之后",
    beforeDestroy() {
    }, //生命周期 - 销毁之前",
    destroyed() {
    }, //生命周期 - 销毁完成",
    activated() {
    } //如果页面有keep-alive缓存功能，这个函数会触发",
  };
</script>
<style scoped>

</style>
